<?php
/**
 * @link https://ym2.cleverstone.top
 * @copyright Copyright (c) 2020 Yii Manager Software LLC
 */

/** @var \yii\web\View $this */
/** @var \builder\form\FormBuilder $context 当前表单组件实例 */
/** @var array $rootLayout 根布局 */
/** @var array $body 表单组内容 */
/** @var string $requiredStyle 必填项标记风格 */
/** @var array $footerLayout 表单尾部布局 */
/** @var array $footerBtn 表单尾部按钮 */

$context = $this->context;
?>

<div class="ym2-form-ui card border-0 <?= $rootLayout['class'] ?>" style="<?= $rootLayout['style'] ?>" ng-controller="ym2.ctrl.<?= $context->id ?>"<?= $rootLayout['attribute'] ?>>
    <div class="card-body">
        <!--开始表单-->
        <?= $context->beginForm() ?>

        <form class="card-body px-1 pt-0">
            <div class="row">
                <!--表单分组-->
                <?php foreach ($body as $groupField => $options): ?>

                <div class="col-md-<?= $options['layout'] ?> <?= $options['class'] ?>"<?= $options['attribute'] ?> style="<?= $options['style'] ?>">
                    <div class="layui-card mb-2 shadow-none">
                        <!--分组名称-->
                        <?php if (strcasecmp($groupField, 'default') && !empty($options['title'])): ?>

                        <div class="layui-card-header border-bottom-0 mb-2 header-left-border">
                            <span class="f15 font-weight-lighter"><?= $options['title'] ?></span>
                            <!--分组注释-->
                            <comment class="layui-font-gray pl-1 f12"><?= $options['comment'] ?></comment>
                        </div>
                        <?php endif; ?>

                        <!--表单控件-->
                        <?php if (!empty($options['controls'])): ?>

                        <div class="layui-card-body py-0 row">
                            <?= $this->renderPhpFile(
                                __DIR__ . '/tpl/view.form.control.php',
                                [
                                    'controlItems' => $options['controls'],
                                    'requiredStyle' => $requiredStyle,
                                    'groupField' => $groupField,
                                ]) ?>

                        </div>
                        <?php endif; ?>

                    </div>
                </div>
                <?php endforeach; ?>

            </div>

            <!--结束表单-->
            <?= $context->endForm() ?>

            <?php if (!empty($footerBtn)): ?>

            <div class="card-body pb-0 <?= $footerLayout['class'] ?>"
                 style="<?= $footerLayout['style'] ?>"
                 <?= $footerLayout['attribute'] ?>>

                <?php foreach ($footerBtn as $type => $item): ?>
                <?php switch ((string)$type): case 'submit': //提交按钮 ?>

                <button class="layui-btn layui-btn-sm layui-btn-theme ym2-form-submit-ui" ng-click="formSubmit()"><?= $item['title'] ?></button>
                <?php break; case 'reset': //重置按钮 ?>

                <button type="button" class="layui-btn layui-btn-sm layui-btn-primary ym2-form-reset-ui" ng-click="formReset()"><?= $item['title'] ?></button>
                <?php break; case 'close': //关闭按钮 ?>

                <button type="button" class="layui-btn layui-btn-sm layui-btn-gray ym2-form-close-ui" ng-click="formClose()"><?= $item['title'] ?></button>
                <?php break; case 'back': //返回按钮 ?>

                <button type="button" class="layui-btn layui-btn-sm layui-btn-gray ym2-form-back-ui" ng-click="formBack()"><?= $item['title'] ?></button>
                <?php break; default: //额外的按钮 ?>

                <?= $item['content'] ?>
                <?php endswitch; ?>
                <?php endforeach; ?>

            </div>
            <?php endif; ?>

        </form>
    </div>

</div>
